package com.cnap.multiclouldmgmt.model.enums;


import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * ------
 *告警级别枚举
 * @data 202211
 * @version 1.0
 * @describe
 * @author xc
 * ----
 **/
public enum ErrorInjectOrderEnum {
    /**
     * 节点随机指定核数故障模拟
     */
    NodeCpuNum("node_cpu_num", "节点随机指定核数故障模拟",
            "blade create cpu fullload --cpu-count 2","节点"),
    /**
     * 节点CPU 故障模拟
     */
    NodeCpuError("node_cpu_error", "节点CPU故障模拟",
            "blade create k8s node-cpu fullload --names xxx --cpu-percent 80 --kubeconfig ~/.kube/config",
            "节点"),
    /**
     * 节点容器组cpu故障模拟
     */
    NodePodsCpuError("node_pods_cpu_error", "节点容器组cpu故障模拟" ,
            "blade create k8s container-cpu fullload --cpu-percent 100 --container-ids xxx --names xxx --namespace xxx --kubeconfig config",
            "节点|容器组"),

    /**
     * 节点网络延迟故障模拟
     */
    NetDelayError("net_delay_error", "节点网络延迟故障模拟",
            "./blade create network delay --interface th0  --time 1500","节点"),
    /**
     * 紧急级别
     */
    MicroSvcPress("micro_svc_press", "微服务压力测试",
                          "用户数： 150；启动时间：1s; 循环次数： 1","微服务"),

    /**
     * gpu_error
     */
    GpuError("gpu_error", "gpu服务故障注入",
            "burinnig gpu","节点");

    private final String errorKey;
    private final String errorDescribe;
    private final String errorOrder;
    private final String errorResType;


    ErrorInjectOrderEnum(String errorKey, String errorDescribe, String errorOrder,String errorResType) {
        this.errorKey = errorKey;
        this.errorDescribe = errorDescribe;
        this.errorOrder = errorOrder;
        this.errorResType = errorResType;
    }

    public static boolean checkErrorInjectRunOrder(String errorKey){

        if (StringUtils.equalsIgnoreCase(errorKey,ErrorInjectOrderEnum.GpuError.getErrorKey())){
            return false;
        }

        if (StringUtils.equalsIgnoreCase(errorKey,ErrorInjectOrderEnum.MicroSvcPress.getErrorKey())){
            return false;
        }

        return true;

    }

    public static String getErrorResTypeByKey(String errorKey){

        for(ErrorInjectOrderEnum enumObj : ErrorInjectOrderEnum.values()){

            if (StringUtils.equalsIgnoreCase(errorKey,enumObj.getErrorKey())){

                return enumObj.getErrorResType();
            }
        }

        return errorKey;
    }

    public static String getErrorDescribeByKey(String errorKey){

        for(ErrorInjectOrderEnum enumObj : ErrorInjectOrderEnum.values()){

            if (StringUtils.equalsIgnoreCase(errorKey,enumObj.getErrorKey())){

                return enumObj.getErrorDescribe();
            }
        }

        return errorKey;
    }

    /**
     * get
     *
     * @return ErrorResType
     */
    public String getErrorResType() {
        return errorResType;
    }

    /**
     * get
     *
     * @return ErrorName
     */
    public String getErrorKey() {
        return errorKey;
    }

    /**
     * get
     *
     * @return ErrorDescribe
     */
    public String getErrorDescribe() {
        return errorDescribe;
    }

    /**
     * get
     *
     * @return ErrorOrder
     */
    public String getErrorOrder() {
        return errorOrder;
    }
}
